﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace Fares
{
    public partial class ArticoleSearchFrm : FrmCard
    {
        private DataSets.ESRPDataSetArticol.ArticoleDataTable ArticoleDT = null;

        public ArticoleSearchFrm(ModuleClass mc, DataSets.ESRPDataSetArticol.ArticoleDataTable adt)
            : base(mc)
        {
            InitializeComponent();
            ArticoleDT = adt;
            workConnString = mc.workConnectionString;
            ActiveControl = codArticolTB;
            EnableMainBrowseButton = false;
        }

        private void ArticoleSearchFrm_Load(object sender, EventArgs e)
        {
            
            SqlConnection con = DeschideConexiune(workConnString);
            this.tipCategoriiArticoleTableAdapter.Connection = con;
            this.tipCategoriiArticoleTableAdapter.Fill(this.esrpDataSetArticol.TipCategoriiArticole);
            conturiTableAdapter.Connection = con;
            conturiTableAdapter.Fill(esrpDataSetArticol.Conturi, ModuleInfo.CodUnitate);
            InchideConexiune(con);
            contContCB.SelectedItem = null;
            contDenumireCB.SelectedItem = null;
            comboBox1.SelectedItem = null;
            comboBox2.SelectedItem = null;


            AddButton("Filtreaza[F9]", global::ERPStudio.Properties.Resources._001_371, Cauta1, ToolStripItemAlignment.Right, false);
            AddButton("Anuleaza Filtru", global::ERPStudio.Properties.Resources._001_39, AnuleazaCauta, ToolStripItemAlignment.Right, false);
            HandleSalvare += Cauta1;
        }

        private void Cauta1(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            String contArt = String.Empty,contChelt = String.Empty;
            if(conturiBindingSource.Current!=null)
            {
                DataSets.ESRPDataSetArticol.ConturiRow cr = ((DataRowView)conturiBindingSource.Current).Row as DataSets.ESRPDataSetArticol.ConturiRow;
                contArt = cr.Cont;
            }

            if(conturiBindingSource.Current!=null)
            {
                DataSets.ESRPDataSetArticol.ConturiRow cr = ((DataRowView)conturiBindingSource1.Current).Row as DataSets.ESRPDataSetArticol.ConturiRow;
                contChelt = cr.Cont;
            }
            articoleTableAdapter.Connection = con;
            articoleTableAdapter.Cauta(ArticoleDT, ModuleInfo.CodUnitate, codArticolTB.Text, denumireTB.Text, contContCB.Text, comboBox2.Text, Convert.ToInt16(categorieCB.SelectedValue));
            InchideConexiune(con);
        }

        private void AnuleazaCauta(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            articoleTableAdapter.Connection = con;
            articoleTableAdapter.Cauta(ArticoleDT, ModuleInfo.CodUnitate, String.Empty, String.Empty, String.Empty, String.Empty,-1);
            InchideConexiune(con);
        }
    }
}
